//
//  MeViewController.swift
//  SwitfTest
//
//  Created by runone02 on 2018/12/28.
//  Copyright © 2018年 liqiyun. All rights reserved.
//

import UIKit

class MeViewController: BaseViewController,UITableViewDelegate,UITableViewDataSource {
    var tableView :UITableView!
    var topBgView :UIView!
    let titleArr = ["图片单选",
                     "图片单选+剪裁",
                     "图片单选+剪裁(比例可定制)",
                     "图片单选+可以编辑图片(涂鸦操作)",
                     "多选视频和图片不能同时操作",
                     "隐藏图片文件，展示视频文件",
                     "配置导航栏的颜色和文字颜色",
                     "底部弹出样式只展示图片",
                     "相机在外部单选可编辑",
                     "相机在外部单选剪裁指定比例",
                     "指定tineColor"]
    let _imageArr = ["","","","",""]
    
    override func viewDidLoad() {
        super.viewDidLoad()
        view.backgroundColor = UIColor.white
        _init()

    }
    
    /// 配置tableView
    func _init(){

        automaticallyAdjustsScrollViewInsets = false
        tableView = UITableView(frame: CGRect(x: 0, y: 0, width: SCREEN_WIDTH, height: SCREEN_HEIGHT), style: .grouped)
        tableView.dataSource = self
        tableView.delegate = self
        tableView.register(MeTopCell.self,forCellReuseIdentifier: "MeTopCell")   //头部
        tableView.register(MeBaseViewCell.self,forCellReuseIdentifier: "MeBaseCell")   //其他cell
        tableView.register(PicViewCell.self,forCellReuseIdentifier: "PicViewCell")   //照片cell
        tableView.register(VideoViewCell.self,forCellReuseIdentifier: "VideoViewCell")   //视频cell
        
        
        tableView.sectionFooterHeight = 10
        tableView.sectionHeaderHeight = 0
        tableView.tableHeaderView = UIView(frame: CGRect(x: 0, y: 0, width: 0, height: CGFloat.leastNonzeroMagnitude))
        view.addSubview(tableView)
        
        tableView.separatorColor = RGBAlpa(232,232,232,1)
        tableView.showsVerticalScrollIndicator = false
        tableView.showsHorizontalScrollIndicator = false
    }
    


    override func didReceiveMemoryWarning() {
        super.didReceiveMemoryWarning()
        // Dispose of any resources that can be recreated.
    }
    
    func numberOfSections(in tableView: UITableView) -> Int {
        return 5
    }
    
    func tableView(_ tableView: UITableView, numberOfRowsInSection section: Int) -> Int {
        if (section == 0) {
            return 1
        }else if (section == 1){
            return 1
        }else if(section == 2){
            return 1
        }
        else if (section == 3){
            return titleArr.count
        }else{
            return 1;
        }
    }
    
    func tableView(_ tableView: UITableView, heightForRowAt indexPath: IndexPath) -> CGFloat {
        if  (indexPath.section == 0) {
            return SCREEN_HEIGHT/4
        } else if(indexPath.section == 1){
            return 120
        }else if(indexPath.section == 2){
            return 120
        }
        else{
            return 60
        }
    }
    
    
    
    func tableView(_ tableView: UITableView, cellForRowAt indexPath: IndexPath) -> UITableViewCell {
        if (indexPath.section == 0) {
            let cell = tableView.dequeueReusableCell(withIdentifier:  "MeTopCell", for: indexPath) as! MeTopCell
            return cell
        }else if(indexPath.section == 1){
            let picViewCell = tableView.dequeueReusableCell(withIdentifier:  "PicViewCell", for: indexPath) as! PicViewCell
            return picViewCell
        }else if(indexPath.section == 2){
            
            let videoViewCell = tableView.dequeueReusableCell(withIdentifier:  "VideoViewCell", for: indexPath) as! VideoViewCell
            return videoViewCell
        }
        
        let cell = tableView.dequeueReusableCell(withIdentifier:  "MeBaseCell", for: indexPath) as! MeBaseViewCell
        cell.nameLabel.text = titleArr[indexPath.row]
        return cell
    }
    
    
    func tableView(_ tableView: UITableView, didSelectRowAt indexPath: IndexPath) {

        if (indexPath.section == 3){
            if(indexPath.row == 0){ //图片单选
                let imagePickTool = CLImagePickerTool()
                imagePickTool.singleImageChooseType = .singlePicture
                imagePickTool.setupImagePickerWith(MaxImagesCount: 6, superVC: self) { (asset,editorImage) in
                    //返回图片
                }
            }else if(indexPath.row == 1){  //图片单选+剪裁
                let imagePickTool = CLImagePickerTool()
                imagePickTool.singleImageChooseType = .singlePictureCrop
                imagePickTool.setupImagePickerWith(MaxImagesCount: 6, superVC: self) { (asset,editorImage) in

                    //返回图片
                }
            }else if(indexPath.row == 2){//图片单选+剪裁(比例可定制)
                let imagePickTool = CLImagePickerTool()
                imagePickTool.singleImageChooseType = .singlePictureCrop
                imagePickTool.singlePictureCropScale = 2
                imagePickTool.setupImagePickerWith(MaxImagesCount: 6, superVC: self) { (asset,editorImage) in
                    //返回图片
                }
            }else if (indexPath.row == 3){//图片单选+可以编辑图片(涂鸦)
                let imagePickTool = CLImagePickerTool()
                imagePickTool.singleImageChooseType = .singlePicture
                imagePickTool.singleModelImageCanEditor = true
                imagePickTool.setupImagePickerWith(MaxImagesCount: 6, superVC: self) { (asset,editorImage) in
                    //返回图片
//                    self.img.image = editorImage
                }
            }
            else if(indexPath.row == 4){//多选视频和图片不能同时操作
                let imagePickTool = CLImagePickerTool()
                imagePickTool.onlyChooseImageOrVideo = true
                imagePickTool.setupImagePickerWith(MaxImagesCount: 6, superVC: self) { (asset,editorImage) in
                    //返回图片
                }
            }
            else if(indexPath.row == 5){ //隐藏图片文件，展示视频文件
                let imagePickTool = CLImagePickerTool()
                imagePickTool.isHiddenImage = true
                imagePickTool.setupImagePickerWith(MaxImagesCount: 6, superVC: self) { (asset,editorImage) in
                    
                }
            }

            else if(indexPath.row == 6){////底部弹出样式只展示图片
//                let imagePickTool = CLImagePickerTool()
//                imagePickTool.cl_setupImagePickerAnotherWayWith(maxImagesCount: 1, superVC: self) { (asserArr, img) in
//                    print("成功返回\(asserArr)")
//                }
                print("未实现")
            }else if(indexPath.row == 7){
                let imagePickTool = CLImagePickerTool()
                imagePickTool.cl_camera()
                imagePickTool.clPickerToolClouse = {(assetArr,img) in
                    print(assetArr)
                    print(img ?? "nil")
//                    self.imageView.image = img
                }
            }else if(indexPath.row == 8){ // //相机在外部单选可编辑
                let imagePickTool2 = CLImagePickerTool()
                imagePickTool2.cameraOut = true
                imagePickTool2.isHiddenVideo = true
                imagePickTool2.singleImageChooseType = .singlePicture
                imagePickTool2.singleModelImageCanEditor = true
                imagePickTool2.cl_setupImagePickerWith(MaxImagesCount: 6, superVC: self) { (asset,editorImage) in
//                    self.imageView.image = editorImage
                }
            }else if(indexPath.row == 9){ //相机在外部单选剪裁指定比例
                let imagePickTool3 = CLImagePickerTool()
                imagePickTool3.cameraOut = true
                imagePickTool3.isHiddenVideo = true
                imagePickTool3.singlePictureCropScale = 2
                imagePickTool3.singleImageChooseType = .singlePictureCrop
                imagePickTool3.cl_setupImagePickerWith(MaxImagesCount: 6, superVC: self) { (asset,editorImage) in
//                    self.imageView.image = editorImage
                }
            }else if(indexPath.row == 10){
                let imagePickTool5 = CLImagePickerTool()
                imagePickTool5.tineColor = UIColor.black
                imagePickTool5.cl_setupImagePickerWith(MaxImagesCount: 6, superVC: self) { (asset,editorImage) in
//                    self.imageView.image = editorImage
                }
            }
        }

        else{

            let vc = LoginViewController()
            PresentTransition.presentWithAnimate(fromVC: self,
                                                 toVC: vc,
                                                 duration: 0.5,
                                                 animate: .scale)
//            PushTransition.pushWithTransition(fromVC: self,
//                                              toVC: vc,
//                                              type: .fromBottom,
//                                              duration: 0.2)
        }
    }

  
}
